{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Project #2: Understanding root and equation systems\n",
    "\n",
    "\n",
    "- 姓名:\n",
    "- 学号:\n",
    "- 邮箱:\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. Root（方程求根）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1 Fix point iteration（不动点迭代法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义迭代函数\n",
    "def CalXNew(XOld):\n",
    "    XNew = 5 / XOld / (1 + XOld) + XOld / (1 + XOld)\n",
    "    return XNew"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "XOld = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CalXNew(XOld)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "iList = []\n",
    "XNewList = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "XNewList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 1.7099669239736828\n"
     ]
    }
   ],
   "source": [
    "# start iteration\n",
    "for i in range(100):\n",
    "    XNew = CalXNew(XOld)\n",
    "    XOld = XNew\n",
    "    iList.append(i)\n",
    "    XNewList.append(XNew)\n",
    "print(i, XNew)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# iList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# XNewList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Xnew')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEGCAYAAAB/+QKOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAA28UlEQVR4nO3deZxcdZ3v/9enTlXvnc7W2VdWBZTFGEFA0BEFFRnner3AyCxXRR28ozM+xquzOOP85udv7jjjb0ZBGVQGGLfrAgxX2UdkEVmSGCAQCCGQfemsnV6rq+pz/zjnVJ3aQoek0kn3+/l49CNV33Oq+ns6SX368/18v99j7o6IiEil1Fh3QEREjk4KECIiUpMChIiI1KQAISIiNSlAiIhITemx7sDhNH36dF+0aNFYd0NE5JixfPnyne7eXevYuAoQixYtYtmyZWPdDRGRY4aZra93TENMIiJSkwKEiIjUpAAhIiI1KUCIiEhNChAiIlJTwwKEmbWY2RNm9pSZPWtmX6pxjpnZ18xsrZk9bWZnJY5dbGYvRMc+36h+iohIbY3MIIaBd7j76cAZwMVmdnbFOZcAJ0ZfVwPfB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HDvwfON7OV0b0BAjP7ipk9aWZPm9nHo/MvjO6N8X3gmajtdjNbHt1P4Oqo7e8JdwddaWbfS34vC30luvfAM2b23xLv/cvEvRi+F63srezzL83sf5nZE2a2xszOj9rLMgAz+5mZXRh/7+g1y83sfjNbGr3POjN7f+Lt55vZ3dH+/3+deK8PR99vpZn9axwMovf9WzN7HDjn0P9GZNwY61WB+tLXoX4BfdGfFxKtlo6eXw38ZfS4mXBl8eLovH5gceLcqdGfrYQrcacl37vG9/ovwH2E9x2YSbjVw+zovfcR7nmTAn4NnFejz78E/il6/B7g/ujxHwDXJs77GXBh9NiJVsICtwH3AhnC+z2sTLx+K+HK2vhalgCvB/4PkInO+wbwe4n3/dBY/z3q6+j7Sh90RBE5drwLeKOZfTB63kW4F00WeMLD/fFjf2xmH4gez4/O23WA9z4P+IG75wk3SnsQeDPQG733JgAzW0k49PVIjfeIN0xcHp3zarLA3dHjZ4Bhdx8xs2cqXn+fu++Kvv+tUV9zwJuAJ6OEppXShm55wk0cRcooQMh4ZsD/cPd7yhrDIZv+iufvBM5x9wEz+yXQMor3rmc48ThP/f9nwzXOyVE+9Jvsx4i7x3vjFOLXu3shuklOrHL/HI/6e7O7f6FGP4aiQCdSRjUIGU/2A52J5/cAn4y2OcfMTopunFOpC9gTBYfXEd6SNTYSv77CQ8B/i+oc3YR3cBv9Lpn1vQKcYWYpM5vPQdz9K+EiC+9R3Ep4Z7FfEW7g9kEzmwHFexgvPAz9lXFMGYSMJ08DOTN7ivC+vf9COPSyIioU91D7lpN3A58ws6cJd7x8LHHsBuBpM1vh7r+baL+NsKD7FOFv6J9z921RgDkUvwJeJhxCWgWseA3v8QjhbqYnAN9392UAZvaXwL1mliLcCfQaYP0h9lfGMe3mKiIiNWmISUREalKAEBGRmhQgRESkJgUIERGpSQFCRERqUoAQEZGaFCBERKSm/wuhXfW0I33nzwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(iList, XNewList)\n",
    "plt.xlabel(\"iteration number\")\n",
    "plt.ylabel(\"Xnew\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2 Newton method（牛顿法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(x):\n",
    "    return x**3 - 5 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "def fder(x):\n",
    "    return 3 * x**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fder(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calXnew(Xold):\n",
    "    return Xold - f(Xold) / fder(Xold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "Xold = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.75"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calXnew(Xold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "Xold = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.333333333333333"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calXnew(Xold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "iList = []\n",
    "XnewList = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "XnewList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 1.709975946676697\n"
     ]
    }
   ],
   "source": [
    "# start iteration\n",
    "for i in range(100):\n",
    "    Xnew = calXnew(Xold)\n",
    "    Xold = Xnew\n",
    "    iList.append(i)\n",
    "    XnewList.append(Xnew)\n",
    "print(i, Xnew)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# iList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# XnewList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Xnew')"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEGCAYAAABo25JHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAYT0lEQVR4nO3dfZDdVX3H8ffnPixsgCRoVkQIBhUF6vDkqiiIKVoFq6LVqaKCUjXaMgqW+oRObetMR6sytVrEKBSxiGMhWNQqIIKUB4FNDElICIKIpgZZERICmOxmv/3jd+7m7s3dzc3Db292z+c1s7P34be/+z0T2M+ec37n/BQRmJlZvirdLsDMzLrLQWBmljkHgZlZ5hwEZmaZcxCYmWWu1u0CttecOXNi3rx53S7DzGxKWbx48e8joq/de1MuCObNm8fAwEC3yzAzm1IkPTDeex4aMjPLnIPAzCxzDgIzs8w5CMzMMucgMDPLnIPAzCxzDgIzs8xlEwSrH3yML1yzmoc3bOx2KWZmu5VsguDehzbwpZ/cy+83bOp2KWZmu5VsgqBeFQBDm0e6XImZ2e4loyAomuogMDMbK5sgqKUewfCIb81pZtYsnyCouEdgZtZONkHQU2vMEbhHYGbWLJsgaPQIht0jMDMbI58gqLpHYGbWTmlBIGmupOslrZJ0l6Sz2hxziqRlkpZKGpB0fFn1NK4aGh5xj8DMrFmZdygbBs6JiCWS9gEWS7o2IlY2HXMdcFVEhKQjgO8Ah5ZRjC8fNTNrr7QeQUSsjYgl6fFjwCrggJZjNkREY6xmL6C0cZtaxUNDZmbtTMocgaR5wNHAbW3ee6Oku4EfAH81zs8vSENHA4ODgztUw+jQkIPAzGyM0oNA0t7AFcDZEbG+9f2IuDIiDgXeAHy63TkiYmFE9EdEf19f3w7VsWVBmYeGzMyalRoEkuoUIXBpRCya6NiIuBF4tqQ5ZdTS6BFsGnYQmJk1K/OqIQEXAqsi4rxxj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dDBToxjgqDps6al7d2Z0qY/B4FNCZI2pIefAV4maWnal74q6XOS7pC0TNL70vHz070ZvgUsT699V9LitJf9gvTaZyh2slwq6dLmz1Lhc2nf++WS3tJ07hua7gVwaVrl2lrzDZI+K+l2SfdIell6fcxf9JK+L2l+47PTzyyW9GNJL0rn+aWk1zedfq6kH6X95z/VdK53pM9bKumrjV/66bz/JOk24CU7/y9i00q3V9D5y1+dfAEb0vf5pNXD6fkC4JPp8R4UK20PTsc9DhzcdOxT0vdeilWpT20+d5vPehNwLcWe9/tRbG+wfzr3Ooo9XSrArcDxbWq+AfhCevwa4Mfp8buALzcd931gfnocpJWhwJXANUCd4n4DS5t+fi3FStNGW/qBw4DvAfV03PnA6U3n/ctu/zv6a/f8qm13cpjtXl4FHCHpzen5LIq9VjYBt0exP3vDByW9MT2em457eIJzHw9cFhGbKTb8+inwQmB9OvcaAElLKYasbmpzjsbGf4vTMduyCfhRerwc2BgRQ5KWt/z8tRHxcPr8RanWYeAFwB2pg9LLlo3JNlNsRmi2FQeBTXUCPhARV495sRhqebzl+SuBl0TEE5JuAPbs4Nzj2dj0eDPj/7+0sc0xw4wdlm2uYygiGvu+jDR+PiJG0o1YGlr3holU7zci4uNt6vhjCjSzrXiOwKaax4B9mp5fDfx12n4bSc9NN2hpNQt4JIXAoRS38mwYavx8ixuBt6R5iD6KO4Jt366O7f0KOEpSRdJctvNuUsmfqbiHbS/FnapuptiI7M2Sngaj97h95i6o16Y59whsqlkGDEu6k+K+rl+kGDJZkiZsB2l/m8IfAe+XtIxih8afNb23EFgmaUlEvL3p9SspJlbvpPiL+yMR8WAKkp1xM3A/xdDPCmDJDpzjJoqdN58DfCsiBgAkfRK4RlKFYufKM4EHdrJem+a8+6iZWeY8NGRmljkHgZlZ5hwEZmaZcxCYmWXOQWBmljkHgZlZ5hwEZmaZ+3+HTJrQ6CV2cwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(iList, XnewList)\n",
    "plt.xlabel(\"iteration number\")\n",
    "plt.ylabel(\"Xnew\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3 Bisection（二分法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.4 Secant（割线法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.5 关于方程求根，不同的方法或者算法的优劣的思考\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Equation systems（线性方程组）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 Gauss elimination（高斯消元法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import numpy\n",
    "import numpy as np\n",
    "\n",
    "# 设置numpy打印的有效位数和格式"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Define your problem here（定义你的线性方程组问题）\n",
    "- 用Markdown写出你要求解的方程组\n",
    "- 将该方程组转换成矩阵的形式，并用Markdown表示\n",
    "- 写出对应的矩阵A和向量b\n",
    "- 参考资料：https://zhuanlan.zhihu.com/p/269245898"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 方程组\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "## 矩阵表示\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "## 矩阵A\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "## 向量b\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Convert your problem to python codes（转换成python代码）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = 4\n",
    "# A = np.random.randn(n, n)\n",
    "# b = np.random.randn(n,1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [],
   "source": [
    "b=np.array([ 6,  6,  6, 10.0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {},
   "outputs": [],
   "source": [
    "A=np.array([[ 1, 16, 15,  8],\n",
    "       [14,  7, 12, 18],\n",
    "       [15, 19,  7, 13],\n",
    "       [17,  8,  1,  0.0]])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: elimination（消元）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Old version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1. 16. 15.  8.]\n",
      " [14.  7. 12. 18.]\n",
      " [15. 19.  7. 13.]\n",
      " [17.  8.  1.  0.]]\n"
     ]
    }
   ],
   "source": [
    "A1 = A.copy()\n",
    "b1 = b.copy()\n",
    "print(A1)\n",
    "for i in range(0, n+1):\n",
    "    for j in range(i + 1, n):\n",
    "        C = - A[j, i] / A[i, i]\n",
    "        b1[j] = b[j] + C * b[i]\n",
    "        for k in range(i, n):\n",
    "            A1[j, k] = A[j, k] + C * A[i, k]\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[   1.  ,   16.  ,   15.  ,    8.  ],\n",
       "       [   0.  , -217.  , -198.  ,  -94.  ],\n",
       "       [   0.  ,    0.  ,  -25.57,  -35.86],\n",
       "       [   0.  ,    0.  ,    0.  ,   -1.86]])"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  6.  , -78.  , -10.29,   9.14])"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1., 16., 15.,  8.],\n",
       "       [14.,  7., 12., 18.],\n",
       "       [15., 19.,  7., 13.],\n",
       "       [17.,  8.,  1.,  0.]])"
      ]
     },
     "execution_count": 200,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### new verison"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1. 16. 15.  8.]\n",
      " [14.  7. 12. 18.]\n",
      " [15. 19.  7. 13.]\n",
      " [17.  8.  1.  0.]]\n",
      "4 阶\n",
      "2 行\n",
      "1 列\n",
      "2 列\n",
      "3 列\n",
      "4 列\n",
      "3 行\n",
      "1 列\n",
      "2 列\n",
      "3 列\n",
      "4 列\n",
      "4 行\n",
      "1 列\n",
      "2 列\n",
      "3 列\n",
      "4 列\n",
      "3 阶\n",
      "3 行\n",
      "2 列\n",
      "3 列\n",
      "4 列\n",
      "4 行\n",
      "2 列\n",
      "3 列\n",
      "4 列\n",
      "2 阶\n",
      "4 行\n",
      "3 列\n",
      "4 列\n",
      "1 阶\n",
      "0 阶\n"
     ]
    }
   ],
   "source": [
    "A1 = A.copy()\n",
    "b1 = b.copy()\n",
    "print(A1)\n",
    "for i in range(0, n+1):\n",
    "    print(n-i,\"阶\")\n",
    "    for j in range(i + 1, n):\n",
    "        print(j+1,\"行\")\n",
    "        C = - A1[j, i] / A1[i, i]\n",
    "        b1[j] = b1[j] + C * b1[i]\n",
    "        for k in range(i, n):\n",
    "            A1[j, k] = A1[j, k] + C * A1[i, k]\n",
    "            print(k+1,\"列\")\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1., 16., 15.,  8.],\n",
       "       [14.,  7., 12., 18.],\n",
       "       [15., 19.,  7., 13.],\n",
       "       [17.,  8.,  1.,  0.]])"
      ]
     },
     "execution_count": 202,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {},
   "outputs": [],
   "source": [
    "U=np.triu(A,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1., 16., 15.,  8.],\n",
       "       [ 0.,  7., 12., 18.],\n",
       "       [ 0.,  0.,  7., 13.],\n",
       "       [ 0.,  0.,  0.,  0.]])"
      ]
     },
     "execution_count": 204,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "U"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[   1.  ,   16.  ,   15.  ,    8.  ],\n",
       "       [   0.  , -217.  , -198.  ,  -94.  ],\n",
       "       [   0.  ,   -0.  ,  -16.35,  -11.27],\n",
       "       [   0.  ,    0.  ,    0.  ,  -12.6 ]])"
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  6.  , -78.  ,  -4.56,   6.55])"
      ]
     },
     "execution_count": 206,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question: what are the differences of old and new version?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Your answer\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 2: calculation x（回带求值）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4]"
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(2, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 2, 1, 0]"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(n-1, -1, -1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.zeros(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0., 0., 0., 0.])"
      ]
     },
     "execution_count": 210,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4 行\n",
      "3 行\n",
      "4 列\n",
      "2 行\n",
      "3 列\n",
      "4 列\n",
      "1 行\n",
      "2 列\n",
      "3 列\n",
      "4 列\n"
     ]
    }
   ],
   "source": [
    "for i in range(n-1, -1, -1):\n",
    "    print(i+1,\"行\")\n",
    "    sumX = 0\n",
    "    for k in range(i+1, n):\n",
    "        print(k+1,\"列\")\n",
    "        sumX = sumX + A1[i, k] * x[k]\n",
    "        \n",
    "    x[i] = (b1[i] - sumX) / A1[i, i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.55,  0.  ,  0.64, -0.52])"
      ]
     },
     "execution_count": 212,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 3: verification（计算结果验证）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "metadata": {},
   "outputs": [],
   "source": [
    "# use python matrix library\n",
    "\n",
    "inverseA = np.linalg.inv(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.01,  0.02, -0.03,  0.06],\n",
       "       [ 0.01, -0.06,  0.07, -0.02],\n",
       "       [ 0.08,  0.04, -0.11,  0.05],\n",
       "       [-0.05,  0.03,  0.06, -0.08]])"
      ]
     },
     "execution_count": 214,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inverseA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "metadata": {},
   "outputs": [],
   "source": [
    "x2 = inverseA @ b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.55,  0.  ,  0.64, -0.52])"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# with matrix method\n",
    "x2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.55,  0.  ,  0.64, -0.52])"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# with hand written Guass elimination method\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 4: share your experience here\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
